<template>
	<view>
		<!-- 顶部导航 -->
		<fa-navbar :title="title" :border-bottom="false"></fa-navbar>
		<view class="u-p-30 bg-white">
			<u-form :model="form" ref="uForm" label-width="180">
				<!-- <u-form-item label="输入核销码" prop="verifiycode">
					<u-input v-model="form.verifiycode" />
				</u-form-item> -->
				
				<u-form-item label="输入手机号" prop="mobile">
					<u-input v-model="form.mobile" />
				</u-form-item>
			 
				<!-- <u-form-item label="日期" prop="ydtime"  @click="toBooking()">
					<u-input v-model="form.ydtime" />
				</u-form-item>
				<u-form-item label="置换价格" prop="pricechange">
					<u-input v-model="form.pricechange" />
				</u-form-item>
				<u-form-item label="真实价格" prop="pricereal">
					<u-input v-model="form.pricereal" />
				</u-form-item>
				<u-form-item label="产品名称" prop="goodsname">
					<u-input v-model="form.goodsname" />
				</u-form-item>
				<u-form-item label="手机" prop="mobile">
					<u-input v-model="form.mobile" />
				</u-form-item>
				<u-form-item label="详细地址" prop="address">
					<u-input v-model="form.address" />
				</u-form-item> -->
				<!-- <u-form-item label="所在地区" prop="area_name">
					<u-input type="select" :select-open="cityShow" v-model="form.area_name" placeholder="请选择地区" @click="cityShow = true"></u-input>
				</u-form-item> -->
				<!-- <u-form-item label="详细地址" prop="address">
					<u-input type="textarea" v-model="form.address" />
					<u-button slot="right" type="primary" :custom-style="{ backgroundColor: theme.bgColor, color: theme.color }" size="mini" @click="chooseAddress">
						选择地址
					</u-button>
				</u-form-item>
				<u-form-item label="设为默认地址" :border-bottom="false">
					<u-switch slot="right" :active-color="theme.bgColor" v-model="isdefault" @change="change"></u-switch>
				</u-form-item> -->
			</u-form>
			
	 
			
		</view>
<!-- 		<view>
            1:可以进行扫码核销；2：可以输入核销码。点击查询手动核销
		</view> -->
		<!-- 有问题，这边扫参数获取不到 -->
		<view>
			<u-button hover-class="none"  :custom-style="{ width: '80vw', backgroundColor: '#8B8B7A', color: theme.color }" shape="circle"      @click="scanCode">扫码支付</u-button>
		</view>
		
		<!-- 预订日历 -->
	 
		<!-- 城市 -->
		 
		<view class="footer-bar u-flex u-col-center u-row-center u-border-top">
			<u-button type="primary" :custom-style="{ width: '80vw', backgroundColor: '#007eff', color: theme.color }" shape="circle" hover-class="none" @click="sumbit">
				查询
			</u-button>
		</view>
	</view>
</template>

<script>
export default {
	
	data() {
		return {
			title: '添加地址',
			form: {
				receiver: '',
				mobile: '',
				address: '',
				isdefault: 1,
				area_name: '',
				area_id: ''
			},
			rules: {				 
				mobile: [
					{
						validator: (rule, value, callback) => {
							return this.$u.test.mobile(value);
						},
						message: '手机号码不正确',
						// 可以单个或者同时写两个触发验证方式
						trigger: ['change', 'blur']
					}
				] 
			},
			isdefault: false,
			cityShow: false,
			is_render: false,
			areaCode: [],
			goods_info: {},
			is_show: 1,
			value: false
		};
	},
	onLoad(e) {
		this.id = e.id || '';
		if (e.id) {
			this.title = '编辑';
			// this.getAddressInfo();
		} else {
			this.title = '查询';
			this.is_render = true;
			this.isdefault = this.vuex_address.id ? false : true;
		}
		uni.setNavigationBarTitle({
			title: this.title
		});
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules);
	},
	methods: {
		scanCode(){
						// #ifdef MP || APP-PLUS
						uni.scanCode({
							success:(res)=>{
								console.log("扫码结果 >>>",res)
								if(res.errMsg == 'scanCode:ok'){
									let vercode=this.getQueryString(res.result,'vercode');
									let uid=this.getQueryString(res.result,'uid');
									if(vercode && uid){										// this.goPage('/pages/uform/verificoupdetail?vercode=' + res.data.verifiycode+'&uid='+res.data.user_id);
										
									    this.goPage('/pages/uform/creditpayinfo?vercode='+vercode+'&uid='+uid, true);
										// this.goPage('/pages/signin/signin?vercode'+vercode+'&uid='+uid, true);
									}
								}
							},
							fail(res) {}
						});
						// #endif
		},
		getQueryString(url, name){
		    var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
		    var r = url.substr(1).match(reg)
		    if (r != null) {
		        return r[2]
		    }
		    return null;
		},
		getAddressInfo() {
			this.$api.addressInfo({ id: this.id }).then(res => {
				if (res.code) {
					this.form = Object.assign(this.form, {
						id: this.id,
						receiver: res.data.receiver,
						mobile: res.data.mobile,
						address: res.data.address
					});
					this.isdefault = res.data.isdefault == 1;
					this.areaCode = [res.data.province_id, res.data.city_id, res.data.area_id];
					this.is_render = true;
				} else {
					this.$u.toast(res.msg);
					uni.$u.route({
						type:'back'
					});
				}
			});
		},
		change(value) {
			this.form.isdefault = value ? 1 : 0;
		},
		chooseAddress() {
			uni.chooseLocation({
				success: res => {
					Object.assign(this.form, {
						address: res.address
					});
				}
			});
		},
		//城市选择
		cityResult(e) {
			this.form.area_name = e.province.label + '/' + e.city.label + '/' + e.area.label;
			this.form.area_id = e.area.value;
		},
		sumbit() {
			this.$refs.uForm.validate(valid => {
				if (valid) {
					this.form.odtype="order";
					this.$api.getUinfocommon(this.form).then(res => {
						if (res.code) {
							this.$u.toast(res.msg);
							console.log('tz',res);
							// this.goPage('/pages/uform/verificoupdetail?verifiycode=' + res.data.verifiycode);
							setTimeout(() => {
								this.goPage('/pages/uform/creditpayinfo?vercode=' + res.data.verifiycode+'&uid='+res.data.user_id);
								// uni.$u.route({
								// 	type:'back'
								// })
							}, 1500);
						}else{
											 
							this.$u.toast(res.msg);
						}
					});
				} else {
					console.log('验证失败');
				}
			});
		} 
				 
	}
};
</script>

<style lang="scss">
page {
	background-color: #f4f6f8;
}
</style>
